package org.nnxy.foodboot.controller;

import lombok.RequiredArgsConstructor;
import org.nnxy.foodboot.entity.UserHealth;
import org.nnxy.foodboot.service.UserHealthService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户健康控制器
 */
@RestController
@RequestMapping("/api/user/health")
@RequiredArgsConstructor
public class UserHealthController {
    
    private final UserHealthService userHealthService;
    
    /**
     * 获取用户健康信息
     */
    @GetMapping("/{userId}")
    public Map<String, Object> getUserHealth(@PathVariable Integer userId) {
        UserHealth userHealth = userHealthService.getUserHealthByUserId(userId);
        
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("data", userHealth);
        return result;
    }
    
    /**
     * 保存或更新用户健康信息
     */
    @PostMapping
    public Map<String, Object> saveOrUpdateUserHealth(@RequestBody UserHealth userHealth) {
        boolean success = userHealthService.saveOrUpdateUserHealth(userHealth);
        
        Map<String, Object> result = new HashMap<>();
        if (success) {
            result.put("code", 200);
            result.put("message", "保存成功");
        } else {
            result.put("code", 500);
            result.put("message", "保存失败");
        }
        return result;
    }
} 